<?php

namespace App\Repositories\Admin;

use App\Models\Admin\ComOptionModel;
use App\Models\Admin\CompanyModel;
use App\Models\AreaModel;
use App\Models\User\UsergongchangModel;
use App\Repositories\BaseRepository;

class CompanyRepository extends BaseRepository
{
    protected $repository;
    protected $option;

    public function __construct()
    {
        $this->repository = new CompanyModel();
        $this->option = new ComOptionModel();
    }

    /**
     * ------------------------------------------
     * 企业信息
     * ------------------------------------------
     */

    /**
     * 操作分页获取
     */
    public function getIndexList()
    {
         exit("弃用");
        $models = $this->repository
            ->orderBy('id','desc')
            ->paginate(10);
        $models->limit = 10;
        return $models;
    }

    /**
     * 获取所有公司
     */
    public function getAdminCompanys()
    {
         exit("弃用");
        return $this->repository
            ->orderBy('id','desc')
            ->get();
    }

    /**
     * WEB通过类型，获取公司
     */
    public function getWebCom($facTypes)
    {
         exit("弃用");
        return $this->repository->where('type',1)
            ->whereIn('facType',$facTypes)
            ->count();
    }

    /**
     * WEB通过类型，获取工厂
     */
    public function getWebFac()
    {
         exit("弃用");
        return $this->repository
            ->where('type',2)
            ->skip(0)
            ->take(3)
            ->get();
    }

    /**
     * WEB公司管理中心，通过UID，获取公司信息
     */
    public function getWebCenterOneByUid($uid)
    {
         exit("弃用");
        return $this->repository->where('uid',$uid)->first();
    }

    /**
     * WEB公司管理中心，通过UID，设置公司信息
     */
    public function setWebCenterOneByUid($uid,$data)
    {
         exit("弃用");
        return $this->repository->where('uid',$uid)->update($data);
    }

    /**
     * WEB公司管理中心，通过UID，获取公司可选信息
     */
    public function getWebCenterOptionByUid($uid)
    {
        return $this->option->where('uid',$uid)->first();
    }

    /**
     * WEB公司管理中心，通过UID，设置公司可选信息
     */
    public function setWebCenterOptionByUid($uid,$data)
    {
        return $this->option->where('uid',$uid)->update($data);
    }

//    /**
//     * WEB通过类型，获取公司
//     */
//    public function getWebIndexByCate($type)
//    {
//        //type==1工厂，2公司
//        if ($type==1) {
//            $limit = 3;
//        } else {
//            $limit = 4;
//        }
//        $models = $this->repository
//            ->where('type',$type)
//            ->where('fracType',$type)
//            ->orderBy('id','desc')
//            ->skip(0)
//            ->take($limit)
//            ->get();
//        $dataArr = array();
//        if (!count($models)) { return $dataArr; }
//        foreach ($models as  $key => $model) {
//            $dataArr[$key]['comName'] = $model->com_name ?
//                $model->com_name : '测试公司';
//            $dataArr[$key]['image'] = '';
//            $dataArr[$key]['detail'] = $model->detail ?  $model->detail : '';;
//            $dataArr[$key]['tip'] = '100-1000人 无障碍生产、办公';
//
//        }
//        return $dataArr;
//    }

    /**
     * APP工厂列表
     */
    public function getAppFacs()
    {
         return UsergongchangModel::getModel()
          ////  ->where('type',CompanyModel::type_gongchang)
            ->where('shenhe','!=',0)
            ->where('visible','!=',0)
            ->orderBy('id','desc')
            ->skip(0)
            ->take(3)
            ->get();
        /*
        return $this->repository
            ->where('type',CompanyModel::type_gongchang)
            ->where('shenhe','!=',0)
            ->where('visible','!=',0)
            ->orderBy('id','desc')
            ->skip(0)
            ->take(3)
            ->get();*/
    }

    public function setAdd($data,$type)
    {
         exit("弃用");
      //  var_dump($data,$type);exit;
        $data['created_at'] = time();
        $data['type'] =$type;
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$uid,$type)
    {
         exit("弃用");
        $data['updated_at'] = time();
        return $this->repository->where('uid',$uid)->where('type',$type)
            ->update($data);
    }

    public function setModifyByUid($data,$uid,$type)
    {
         exit("弃用");
      ///  print_r($data);exit;
        $data['updated_at'] = time();
        return $this->repository->where('uid',$uid)->where('type',$type)
            ->update($data);
    }

    public function getShowOne($id,$type=0)
    {
         exit("弃用");
        $model = $this->repository->where('id',$id);
        if ($type) {
            $model = $model->where('type',$type);
        }
        return $model->first();
    }

    /**
     * 通过UID获取 弃用
     */
    public function getShowOneByUid($uid,$type)
    {
         exit("弃用");
        $model = $this->repository->where('uid',$uid)->where('type',$type)->first();
        if (!$model) { return null; }
        if ($model->legal_idcard_imgs) {
            $images = explode('|',$model->legal_idcard_imgs);
            $imageArr = array();
            if ($images[0] && file_exists(ltrim($images[0],'/'))) {
                $imageArr[0] = $images[0];
            } else {
                $imageArr[0] = '';
            }
            if ($images[1] && file_exists(ltrim($images[1],'/'))) {
                $imageArr[1] = $images[1];
            } else {
                $imageArr[1] = '';
            }
            if ($images[2] && file_exists(ltrim($images[2],'/'))) {
                $imageArr[2] = $images[2];
            } else {
                $imageArr[2] = '';
            }
            $model->images = $imageArr;
        } else {
            $model->images = array('','','',);
        }
        $model->cus_like = $model->cus_like ? $model->cus_like : '';
        $model->quality = $model->quality ? $model->quality : '';
        $model->pact = $model->pact ? $model->pact : '';
        if ($model->age_range) {
            $ages = explode(',',$model->age_range);
            $model->ageStart = $ages[0];
            $model->ageEnd = $ages[1];
        } else {
            $model->ageStart = '';
            $model->ageEnd = '';
        }
        $model->outType = $model->out_type ? $model->out_type : '';
        if ($model->param) {
            $model->param = json_decode($model->param);
        }
        if ($model->param2) {
            $model->param2 = json_decode($model->param2);
        }
        return $model;
    }

    /**
     * 后台企业
     */
    public function getAdminShow($id,$type)
    {
         exit("弃用");
        $model = $this->repository->where('id',$id)->where('type',$type)->first();
        if (!$model) { return ''; }
        $model->cateName = $this->getCateNameById($model->cate);
        if ($model->legal_idcard_imgs) {
            $imgs = explode('|',$model->legal_idcard_imgs);
            $model->idcardImg0 = $imgs[0];
            $model->idcardImg1 = $imgs[1];
            $model->idcardImg2 = $imgs[2];
        } else {
            $model->idcardImg0 = '';
            $model->idcardImg1 = '';
            $model->idcardImg2 = '';
        }
        if ($model->age_range) {
            $ages = explode(',',$model->age_range);
            $model->age0 = $ages[0];
            $model->age1 = $ages[1];
        } else {
            $model->age0 = 0;
            $model->age1 = 0;
        }
        //所在城市
       /* if ($model->com_city) {
            $cityParents = $this->getCityParent($model->com_city);
            $model->proviceId = $cityParents['provice']['id'];
            $model->cityId = $cityParents['city']['id'];
            $model->areaId = $cityParents['area']['id'];
            $model->cityFullName = $cityParents['provice']['name']
                .'，'.$cityParents['city']['name']
                .'，'.$cityParents['area']['name'];
        } else {
            $model->proviceId = 0;
            $model->cityId = 0;
            $model->areaId = 0;
            $model->cityFullName = '';
        }*/
        //企业参数
        if ($model->cate==1) {
            $model->params = $this->objToArr($model->param);
            $model->paramFields = array(
                'output' => '年产量',
                'truck' => '送货车辆',
                'piece' => '整件',
                'bale' => '捆包流',
                'single' => '单件流',
                'cut' => '裁剪',
                'back' => '后道',
                'total' => '工厂总人数',
            );
        } else if ($model->cate==2) {
            $model->params = $this->objToArr($model->param2);
            $model->paramFields = array(
                'scale' => '公司规模',
                'totalSale' => '公司销售额',
                'yearSale' => '年销售额',
                'truck' => '送货车辆',
                'brand' => '品牌',
            );
        } else {
            $model->params = $this->objToArr($model->param2);
            $model->paramFields = array(
                'output' => '年产量',
                'truck' => '送货车辆',
                'piece' => '整件',
                'bale' => '捆包流',
                'single' => '单件流',
                'cut' => '裁剪',
                'back' => '后道',
                'total' => '工厂总人数',
                'scale' => '公司规模',
                'totalSale' => '公司销售额',
                'yearSale' => '年销售额',
                'brand' => '品牌',
            );
        }
        //业务类型
        if ($model->out_type) {
            $outTypes = explode('||',$model->out_type);
            $outTypeNames = array();
            foreach ($outTypes as $key => $outType) {
                $outTypeNames[$key] = $this->getCateNameById($outType);
            }
            $model->outTypes = $outTypes;
            $model->outTypeNames = $outTypeNames;
        } else {
            $model->outTypes = array();
        }
        //动态参数
        return $model;
    }

    /**
     * 工厂类型
     */
    public function getCateList()
    {
        return array(
            1 => '仅工厂', '仅公司', '公司含工厂',
        );
    }

    /**
     * 性别
     */
    public function getSexList()
    {
        return array(
            1 => '男', '女',
        );
    }

    /**
     * 工厂类型名称
     */
    public function getCateNameByCate($cate)
    {
        $cates = $this->getCateList();
        return array_key_exists($cate,$cates) ? $cates[$cate] : '';
    }

    /**
     * 性别名称
     */
    public function getSexNameBySex($sex)
    {
        $sexs = $this->getSexList();
        return array_key_exists($sex,$sexs) ? $sexs[$sex] : '';
    }

    /**
     * ------------------------------------------
     * 企业信息
     * ------------------------------------------
     */





    /**
     * ------------------------------------------
     * 企业可选信息
     * ------------------------------------------
     */

    /**
     * 企业可选，获取
     * legal_licences 法人证件json：
        照片photo；
        身份证idcard；
        毕业证graduate；
        证书honor；
        结婚证marry；
        驾驶证drive；
        自定义
     * com_licences 公司证件json：
        组织机构代码证zzjgdmz；
        营业执照yyzz；
        税务登记证swdj；
        租赁合同rent；
        各类许可证licence；
        荣誉证书honor；
        房产证house；
     */
    public function getOptionLicenceByuid($uid,$type)
    {
        $model = $this->option->where('uid',$uid)
            ->where('type',$type)
            ->first();
        if ($model && $model->legal_licences) {
            $model->legals = $this->objToArr($model->legal_licences);
        }
        if ($model && $model->com_licences) {
            $model->coms = $this->objToArr($model->com_licences);
        }
        return $model;
    }

    public function getOptionLicenceArrByuid($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        $dataArr =array(
            'legals' => array(),
            'coms' => array(),
        );
        if ($model && $model->legal_licences) {
//            $dataArr['legals'] = json_decode($model->legal_licences,true);
            $dataArr['legals'] = $this->objToArr($model->legal_licences);
        }
        if ($model && $model->com_licences) {
//            $dataArr['coms'] = json_decode($model->com_licences,true);
            $dataArr['coms'] = $this->objToArr($model->com_licences);
        }
        return $dataArr;
    }

    /**
     * 企业认证，设置
     */
    public function setOptionLicenceByuid($uid,$isExist,$legals,$coms,$type)
    {

        if (!$isExist) {
            $dataArr = array(
                'uid' => $uid,
                'legal_licences' => json_encode($legals),
                'com_licences' => json_encode($coms),
                'created_at' => time(),
                'type'=>$type
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'legal_licences' => json_encode($legals),
                    'com_licences' => json_encode($coms),
                ));
        }
    }

    /**
     * 企业产品，获取
     */
    public function getOptionProList($uid,$type)
    {
       // var_dump($type);exit;
        $model = $this->option
            ->where('uid',$uid)
            ->where('type',$type)

            ->first();
        if ($model && $model->products) {
            $pros = $this->objToArr($model->products);
            return array(
                'zhens' => $pros['zhens'],
                'suos' => $pros['suos'],
                'baos' => $pros['baos'],
            );
        }
        return array(
            'zhens' => array(),
            'suos' => array(),
            'baos' => array(),
        );
    }

    /**
     * 企业产品，设置
     */
    public function setOptionProList($uid,$data,$type)
    {
        $model = $this->option
            ->where('uid',$uid)
            ->where('type',$type)
            ->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'products' => json_encode($data),
                'created_at' => time(),
                'type'=>$type
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'products' => json_encode($data),
                ));
        }
    }

    /**
     * 公司风格，获取
     */
    public function getOptionStyleList($uid,$type)
    {
        $model = $this->option
            ->where('uid',$uid)
            ->where('type',$type)
            ->first();
        if ($model && $model->styles) {
            return explode(",",$model->styles);
        }
        return array();
    }

    /**
     * 企公司风格，设置
     */
    public function setOptionStyleList($uid,$data,$type)
    {
        //var_dump($data);exit;
        $model = $this->option
            ->where('uid',$uid)
            ->where('type',$type)
            ->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'styles' => $data,
                'type'=>$type,
                'created_at' => time(),
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'styles' => $data,
                ));
        }
    }

    /**
     * 产品种类，获取
     */
    public function getOptionProTypesList($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if ($model && $model->pro_types) {
            return $this->objToArr($model->pro_types);
        }
        return array();
    }

    /**
     * 产品种类，获取，json
     */
    public function getOptionProTypeArr($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if ($model && $model->pro_types) {
//            return json_decode($model->pro_types,true);
            return $this->objToArr($model->pro_types);
        }
        return array();
    }

    /**
     * 产品种类，设置
     */
    public function setOptionProTypesList($uid,$data,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if($data){
            $json=json_encode($data);
        }else{
            $json='';
        }

        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'pro_types' => $json,
                'created_at' => time(),
                'type'=>$type
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'pro_types' => $json,
                ));
        }
    }

    /**
     * 款式，获取
     */
    public function getOptionDesignList($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if ($model && $model->designs) {
            return $this->objToArr($model->designs);
        }
        return array();
    }

    /**
     * 款式，获取，json
     */
    public function getOptionDesignArr($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if ($model && $model->designs) {
            return $this->objToArr($model->designs,true);
        }
        return array();
    }

    /**
     * 款式，设置
     */
    public function setOptionDesignList($uid,$data,$tye)
    {
        $model = $this->option->where('uid',$uid)->where('type',$tye)->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'designs' => json_encode($data),
                'created_at' => time(),
                'type'=>$tye
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$tye)
                ->update(array(
                    'designs' => json_encode($data),
                ));
        }
    }

    /**
     * 工厂设备，获取
     */
    public function getOptionEquipList($uid,$type)
    {

        $model = $this->option
            ->where('uid',$uid)
            ->where('type',$type)
            ->first();
        if ($model && $model->equips) {
            return $this->objToArr($model->equips);
        }
    }

    /**
     * 工厂设备，设置
     */
    public function setOptionEquip($uid,$data,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'type' => $type,
                'equips' => json_encode($data),
                'created_at' => time(),
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'equips' => json_encode($data),
                ));
        }
    }

    /**
     * 产量产能，获取
     */
    public function getOptionYield($uid,$type)
    {
      //  var_dump($type);exit;
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if ($model && $model->yields) {
            return json_decode($model->yields);
        }
        $dataArr = array(
            'departs' => array(
                array('key'=>'生产线','num'=>0),
                array('key'=>'检验','num'=>0),
                array('key'=>'全厂总人数','num'=>0),
            ),
            'dayOutPuts' => array(0,0),
            'requirePros' => array(
                array('key'=>'市场货','val'=>0),
                array('key'=>'半精品','val'=>0),
                array('key'=>'全精品','val'=>0),
                array('key'=>'外销','val'=>0),
            ),
            'requireDeparts' => array(
                array('key'=>'组检','num'=>0),
                array('key'=>'尾查','num'=>0),
                array('key'=>'巡检','num'=>0),
            ),
            'standards' => array(0,0,0,0,0),
        );
        return $dataArr;
    }

    /**
     * 产量产能，设置
     */
    public function setOptionYield($uid,$data,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'type' => $type,
                'yields' => json_encode($data),
                'created_at' => time(),
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)->where('type',$type)
                ->update(array(
                    'yields' => json_encode($data),
                ));
        }
    }

    /**
     * 环境，获取
     */
    public function getFacEnvList($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if (!$model || !$model->envs) { return array(); }
        return $this->objToArr($model->envs);
    }

    /**
     * 环境，获取2
     */
    public function getFacEnvJson($uid,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if (!$model || !$model->envs) { return array(); }
        return $model->envs;
    }

    /**
     * 环境，设置
     */
    public function setFacEnvByUid($uid,$data,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        if (!$model) {
            $dataArr = array(
                'uid' => $uid,
                'envs' => json_encode($data),
                'created_at' => time(),
            );
            return $this->option->insertGetId($dataArr);
        } else {
            return $this->option->where('uid',$uid)
                ->update(array(
                'envs' => json_encode($data),
            ));
        }
    }

    /**
     * ------------------------------------------
     * 企业可选信息
     * ------------------------------------------
     */





    /**
     * ------------------------------------------
     * 企业可选信息后台设置
     * ------------------------------------------
     */

    /**
     * 后台获取可选信息
     */
    public function getAdminOptionByUid($uid,$cate=1,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        $resOption = $this->getOptionInit();
        if (!$model) { return $resOption; }
        $dataArr = array();
        if ($model->legal_licences) {
            $dataArr['legals'] = $this->objToArr($model->legal_licences);
        }
        if ($model->com_licences) {
            $dataArr['coms'] = $this->objToArr($model->com_licences);
        }
        if ($model->products) {
            $proArr = array();
            $products = $this->objToArr($model->products);
            if (isset($products['zhens'])) {
                foreach ($products['zhens'] as $product) {
                    //男装
                    $zhen1['type'] = 1;
                    $zhen1['typeName'] = '针织类';
                    $zhen1['cateId'] = $product[0];
                    $zhen1['cateName'] = $this->getCateNameById($product[0]);
                    $zhen1['isExit'] = $product[1];
                    $zhen1['proName'] = '男装';
                    $proArr[] = $zhen1;
                    //女装
                    $zhen2['type'] = 1;
                    $zhen2['typeName'] = '针织类';
                    $zhen2['cateId'] = $product[0];
                    $zhen2['cateName'] = $this->getCateNameById($product[0]);
                    $zhen2['isExit'] = $product[2];
                    $zhen2['proName'] = '女装';
                    $proArr[] = $zhen2;
                    //童装
                    $zhen3['type'] = 1;
                    $zhen3['typeName'] = '针织类';
                    $zhen3['cateId'] = $product[0];
                    $zhen3['cateName'] = $this->getCateNameById($product[0]);
                    $zhen3['isExit'] = $product[3];
                    $zhen3['proName'] = '童装';
                    $proArr[] = $zhen3;
                }
            }
            if (isset($products['suos'])) {
                foreach ($products['suos'] as $product) {
                    //男装
                    $suo1['type'] = 2;
                    $suo1['typeName'] = '梭织类';
                    $suo1['cateId'] = $product[0];
                    $suo1['cateName'] = $this->getCateNameById($product[0]);
                    $suo1['isExit'] = $product[1];
                    $suo1['proName'] = '男装';
                    $proArr[] = $suo1;
                    //女装
                    $suo2['type'] = 2;
                    $suo2['typeName'] = '梭织类';
                    $suo2['cateId'] = $product[0];
                    $suo2['cateName'] = $this->getCateNameById($product[0]);
                    $suo2['isExit'] = $product[2];
                    $suo2['proName'] = '女装';
                    $proArr[] = $suo2;
                    //童装
                    $suo3['type'] = 2;
                    $suo3['typeName'] = '梭织类';
                    $suo3['cateId'] = $product[0];
                    $suo3['cateName'] = $this->getCateNameById($product[0]);
                    $suo3['isExit'] = $product[3];
                    $suo3['proName'] = '童装';
                    $proArr[] = $suo3;
                }
            }
            if (isset($products['baos'])) {
                foreach ($products['baos'] as $product) {
                    //男装
                    $bao1['type'] = 3;
                    $bao1['typeName'] = '箱包类';
                    $bao1['cateId'] = $product[0];
                    $bao1['cateName'] = $this->getCateNameById($product[0]);
                    $bao1['isExit'] = $product[1];
                    $bao1['proName'] = '男装';
                    $proArr[] = $bao1;
                    //女装
                    $bao2['type'] = 3;
                    $bao2['typeName'] = '箱包类';
                    $bao2['cateId'] = $product[0];
                    $bao2['cateName'] = $this->getCateNameById($product[0]);
                    $bao2['isExit'] = $product[2];
                    $bao2['proName'] = '女装';
                    $proArr[] = $bao2;
                    //童装
                    $bao3['type'] = 3;
                    $bao3['typeName'] = '箱包类';
                    $bao3['cateId'] = $product[0];
                    $bao3['cateName'] = $this->getCateNameById($product[0]);
                    $bao3['isExit'] = $product[3];
                    $bao3['proName'] = '童装';
                    $proArr[] = $bao3;
                }
            }
            $dataArr['pros'] = $products;
            $dataArr['products'] = $proArr ? $proArr : array();
        } else {
            $dataArr['pros'] = array();
            $dataArr['products'] = array();
        }
        if ($model->styles) {
            $styleArr = array();
            $styles = $this->objToArr($model->styles);
            foreach ($styles as $style) {
                $cateName = $this->getCateNameById($style[0]);
                $styleNew = array(
                    'id' => $style[0],
                    'name' => $cateName,
                    'isExist' => $style[1]?1:0,
                );
                $styleArr[] = $styleNew;
            }
            $dataArr['styles'] = $styleArr;
        } else {
            $dataArr['styles'] = $resOption['styles'];
        }
        if ($model->pro_types) {
            $dataArr['proTypes'] = $this->objToArr($model->pro_types);
        } else {
            $dataArr['proTypes'] = $resOption['proTypes'];
        }
        if ($model->designs) {
            $dataArr['designs'] = $this->objToArr($model->designs);
        } else {
            $dataArr['designs'] = $resOption['designs'];
        }
        if ($model->equips) {
            $dataArr['equips'] = $this->objToArr($model->equips);
        } else {
            $dataArr['equips'] = $resOption['equips'];
        }
        if ($model->yields) {
            $yields = $this->objToArr($model->yields);
            $dataArr['departs'] = $yields['depart'];
            $dataArr['dayOutPuts'] = $yields['dayOutPut'];
            $dataArr['requirePros'] = $yields['requirePro'];
            $dataArr['requireDeparts'] = $yields['requireDepart'];
            $dataArr['standards'] = $yields['standards'];
        } else {
            $dataArr['departs'] = $resOption['departs'];
            $dataArr['dayOutPuts'] = $resOption['dayOutPuts'];
            $dataArr['requirePros'] = $resOption['requirePros'];
            $dataArr['requireDeparts'] = $resOption['requireDeparts'];
            $dataArr['standards'] = $resOption['standards'];
        }
        if ($model->envs) {
            if ($cate==1) {
                $dataArr['facEnvs'] = $this->objToArr($model->envs);
                $dataArr['comEnvs'] = $resOption['comEnvs'];
            } else {
                $dataArr['comEnvs'] = $this->objToArr($model->envs);
                $dataArr['facEnvs'] = $resOption['facEnvs'];
            }
        } else {
            $dataArr['facEnvs'] = $resOption['facEnvs'];
            $dataArr['comEnvs'] = $resOption['comEnvs'];
        }
        return $dataArr;
    }

    /**
     * 后台设置可选信息
     */
    public function setAdminOptionByUid($uid,$data,$cate,$type)
    {
        $model = $this->option->where('uid',$uid)->where('type',$type)->first();
        $yields = array(
            'depart' => $data['departs'],
            'dayOutPut' => $data['dayOutPuts'],
            'requirePro' => $data['requirePros'],
            'requireDepart' => $data['requireDeparts'],
            'standards' => $data['standards'],
        );
        $envs = $cate==1 ? $data['facEnvs'] : $data['comEnvs'];
        $styles = array();
        if ($resStyles=$data['styles']) {
            foreach ($resStyles as $resStyle) {
                $styleArr[0] = $resStyle['id'];
                $styleArr[1] = $resStyle['isExist'];
                $styles[] = $styleArr;
            }
        }
        $dataArr = array(
            'legal_licences' => json_encode($data['legals']),
            'com_licences' => json_encode($data['coms']),
            'products' => json_encode($data['pros']),
            'styles' => json_encode($styles),
            'pro_types' => json_encode($data['proTypes']),
            'designs' => json_encode($data['designs']),
            'equips' => json_encode($data['equips']),
            'yields' => json_encode($yields),
            'envs' => json_encode($envs),
        );
        if (!$model) {
            $dataArr['uid'] = $uid;
            $dataArr['created_at'] = time();
            return $this->option->insertGetId($dataArr);
        }
        $dataArr['updated_at'] = time();
        $this->option->where('id',$model->id)->update($dataArr);
        return $model->id;
    }

    /**
     * 企业可选信息初始化
     */
    public function getOptionInit()
    {
        $legals = array(
            'photos' => '', 'idcards' => '', 'graduates' => '', 'honors' => '',
            'marrys' => '', 'drives' => '',
        );
        $coms = array(
            'zzjgdmzs' => '', 'yyzzs' => '', 'swdjzs' => '', 'rents' => '',
            'licencess' => '', 'honorss' => '', 'houses' => '',
        );
        $products = array(
//            'zhens' => array(),
//            'suos' => array(),
//            'baos' => array(),
        );
        $styles = array();
        $proTypes = array(
//            array('cate'=>'', 'name'=>'', 'male'=>'',  'female'=>'', 'child'=>''),
        );
        $designs = array(
//            array('name'=>'', 'num'=>''),
        );
        $equips = array(
//            array('', '', '', '', ''),
        );
        $departs = array(
//            array('key'=>'', 'num'=>''),
        );
        $dayOutPuts = array(0,0);
        $requirePros = array(
//            array('key'=>'', 'val'=>''),
        );
        $requireDeparts = array(
//            array('key'=>'', 'num'=>''),
        );
        $standards = array(0,0,0,0,0);
        $facEnvs = array(
            'managers' => array(), 'facManagers' => array(), 'finances' => array(),
            'guards' => array(), 'shapes' => array(), 'raws' => array(),
            'techs' => array(), 'works' => array(), 'backs' => array(),
            'cuts' => array(), 'dorms' => array(), 'samples' => array(),
        );
        $comEnvs = array(
            'managers' => array(), 'manager2s' => array(), 'directors' => array(),
            'handles' => array(), 'finances' => array(), 'officers' => array(),
            'sales' => array(), 'expands' => array(), 'designs' => array(),
            'buyers' => array(), 'sellers' => array(), 'produces' => array(),
            'qcs' => array(), 'storages' => array(), 'transports' => array(),
            'outs' => array(), 'meetings' => array(), 'halls' => array(),
            'stages' => array(), 'talks' => array(), 'cooks' => array(),
            'wcs' => array(), 'teas' => array(), 'dorms' => array(),
        );
        return array(
            'legals' => $legals, 'coms' => $coms,
            'products' => $products, 'styles' => $styles,
            'proTypes' => $proTypes, 'designs' => $designs,
            'equips' => $equips, 'departs' => $departs,
            'dayOutPuts' => $dayOutPuts, 'requirePros' => $requirePros,
            'requireDeparts' => $requireDeparts, 'standards' => $standards,
            'facEnvs' => $facEnvs, 'comEnvs' => $comEnvs,
        );
    }
}